# 封装一个登录判断
from django.http import JsonResponse


def login_required(view_func):
    def wrapper(request,*args,**kwargs):
        if request.user.is_authenticated:
            return view_func(request,*args,**kwargs)
        else:

            return JsonResponse({"errno": "400",
                                "errmsg": "用户未登录"})
    return wrapper

class LoginRequiredMixin:
    @classmethod
    def as_view(cls, **init_kwargs):
        view = super().as_view(**init_kwargs)
        # 调用登录验证装饰器函数
        return login_required(view)